/*
3.15
time:20201028 12:25 AM
key:1.重复的地方很多所以写了很多个函数
user：ldc
*/

#include <iostream>
using namespace std;

class Node
{
public:
	int data;
	Node* next;
	Node()
	{
		data = 0;
		next = NULL;
	}
};
void creat(Node* head)
{
	//建立单链表
	int i;
	Node* p1 = new Node();
	p1 = head;
	for (i = 0; i < 10; i++)
	{
		p1->next = new Node();
		p1 = p1->next;
	}
}
void write(Node* head)
{
	int range_array[10] = { 0, 9, 1, 8, 2, 7, 3, 6, 4,5 };//乱序数组
	int i;
	Node* p1 = new Node();
	p1 = head;
	for (i = 0; i < 10; i++)
	{
		p1->data = range_array[i];
		p1 = p1->next;
	}
}
void read(Node* head)
{
	Node* p1 = new Node();
	p1 = head;
	while (p1->next != NULL)
	{
		cout << p1->data;
		p1 = p1->next;
	}
}
int max_number(Node* head)
{
	int max;
	Node* p1 = new Node();
	p1 = head;
	max = p1->data;
	while (p1->next != NULL)
	{
		if (p1->data >= max)
		{
			max=p1->data;
		}
		p1 = p1->next;
	}
	return max;
}
int count_number(Node* head)
{
	int count = 0;
	
	Node* p1 = new Node();
	p1 = head;
	while (p1->next != NULL)
	{
		count++;
		p1 = p1->next;
	}
	return count;
}
int average_number(Node* head)
{
	int count = 0;
	int total=0;
	Node* p1 = new Node();
	p1 = head;
	while (p1->next != NULL)
	{

		total += p1->data;
		count++;
		p1 = p1->next;
	}
	return (total /count);
}
int main()
{
	
	Node* head = new Node();
	//建立单链表
	creat(head);
	//遍历单链表输入数据
	write(head);
	//正序遍历
	cout << "正序遍历\n";
	read(head);
	cout << "\n";

	//最大数
	cout << "最大数\n";
	cout<<max_number(head)<<endl;

	//节点个数
	cout << "节点个数\n";
	cout << count_number(head) << endl;

	//平均数
	cout << "平均数\n";
	cout << average_number(head) << endl;

	
	}




